/*
 * @Author: szx
 * @Date: 2023-03-28 16:19:36
 * @LastEditTime: 2023-03-29 15:59:11
 * @Description: 
 * @FilePath: \learn\fullstackopen\part1\part1\part2_19_20\service\persons.js
 */
import axios from 'axios'

const baseUrl = 'http://localhost:3001/api/persons'

const getAll = () => {
    return axios.get(baseUrl).then((response) => response.data)
}

const create = (newPerson) => {
    return axios.post(baseUrl, newPerson).then(res => res.data);
}
const update = (id, personObject) => {
    console.log(`update ${id} ${personObject.name}`)

    return axios.put(`${baseUrl}/${id}`, personObject).then(res => res.data);
}
const remove = (id) => {
    return axios.delete(`${baseUrl}/${id}`).then(res => res.status);
}

export {
    getAll,
    create,
    update,
    remove
}